import time

from pyproj import Proj


# 将真实数据转化为tess坐标
def lon_lat(x, y):
    # p = Proj('+proj=tmerc +lat_0=40.04752343063863 +lon_0=116.2872228823074 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    p = Proj('+proj=tmerc +lat_0=40.04997844922362 +lon_0=116.2899557259879 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    lon, lat = p(x, -y, inverse=False)
    return lon, lat


# 将真实数据转化为51坐标
def lon_lat_51(x, y):
    start_time = time.time()
    # p = Proj('+proj=tmerc +lat_0=40.04752343063863 +lon_0=116.2872228823074 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    p = Proj('+proj=tmerc +lat_0=40.04752343063863 +lon_0=116.2872228823074 +datum=WGS84')
    lon_0, lat_0 = p(x, -y, inverse=True)
    print("真实经纬度", lon_0, lat_0)
    lon, lat = p(lon_0, lat_0, inverse=False)
    print("51经纬度", lon, lat)
    end_time = time.time()
    print("转化耗时", end_time - start_time)
    return lon, lat


# 将tess坐标转化为真实数据
def lon_lat_tess_real(x, y):
    # p = Proj('+proj=tmerc +lat_0=40.04752343063863 +lon_0=116.2872228823074 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    p = Proj('+proj=tmerc +lon_0=116.2872229585798 +lat_0=40.04753227284374 +ellps=WGS84')
    # p = Proj('+proj=tmerc +lat_0=40.04997844922362 +lon_0=116.2899557259879 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    lon, lat = p(x, -y, inverse=True)
    return lon, lat


# 51-tess左边转化为真实数据
# 将tess坐标转化为真实数据
def lon_lat_tess_real_51(x, y):
    # p = Proj('+proj=tmerc +lat_0=40.04752343063863 +lon_0=116.2872228823074 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    p = Proj('+proj=tmerc +lat_0=40.04752343063863 +lon_0=116.2872228823074 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    lon, lat = p(x, -y, inverse=True)
    return lon, lat


# 将tess坐标转化为真实数据
def lon_lat_tess_real_yx(x, y):
    # p = Proj('+proj=tmerc +lat_0=40.04752343063863 +lon_0=116.2872228823074 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    p = Proj('+proj=tmerc +lat_0=40.04997844922362 +lon_0=116.2899557259879 +k=1 +x_0=0 +y_0=0 +datum=WGS84')
    lon, lat = p(x, -y, inverse=True)
    return lon, lat


# 120.01778902788759 30.031786300285184
# -371.10247802734375, -207.12509155273438
# 120.01778917220742,30.02804936596004
# 116.28287428541563 40.045666796487694
if __name__ == '__main__':
    start_time = time.time()
    # for i in range(100):
    #     lon, lat = lon_lat(116.28923712817226, 40.05236426121849)
    #     print(lon, lat)
    lon_lat_51(411.09963126820526, -631.3365072585531)
    end_time = time.time()
    print("转化耗时", end_time - start_time)
    print(lon_lat_tess_real(153.09929,576.91253))
    print(lon_lat_tess_real(159.34085, 551.23022))
